xwidgets https://github.com/QuantStack/xwidgets

A C++ implementation of the Jupyter Widgets Protocol

Xwidgets is a C++ implementation of the Jupyter Widgets Protocol

  • BSD Licensed

Xwidgets provides a fully-fledged backend fir Jupyter Interactive widgets in C++, for the C++ kernel and other xeus-based kernels

Installation:

conda xwidgets -c QuantStack -c conda-forge

Numerical widgets

Defining a Slider Widget


In [ ]:
#include "xwidgets/xslider.hpp"

In [ ]:
xw::slider<double> slider;

slider                 // If the semicolon is ommitted in the last line, the return value is displayed.

In [ ]:
slider.value = 20;      // Modifying properties of widgets triggers the update of the frontend.

In [ ]:
slider.value()          // Reading the value requires using the call operator

In [ ]:
// changine some more properties
slider.max = 40;
slider.style().handle_color = "blue";
slider.orientation = "vertical";
slider.description = "A slider";

In [ ]:
#include "xcpp/xdisplay.hpp"

using xcpp::display;

In [ ]:
display(slider);       // xcpp::display can be called to explicitely trigger a the display of an object.

Using operator chaining to mimic keyword arguments


In [ ]:
auto other_slider = xw::slider_generator<double>()
    .min(-1.0)
    .max(1.0)
    .description("Another slider")
    .finalize();

display(other_slider);

Button widget


In [ ]:
#include <iostream>
#include "xwidgets/xbutton.hpp"

In [ ]:
xw::button bt;

In [ ]:
void foo()
{
    std::cout << "Clicked!" << std::endl;
}

In [ ]:
bt.on_click(foo);
    
bt

In [ ]:
bt.description = "button";

In [ ]:
bt.button_style = "success";

In [ ]:
bt.button_style = "some invalid value";  // values are validated upon assignment

In [ ]:
std::cout << bt.button_style();

Value semantics


In [ ]:
xw::button bt_copy = bt;

In [ ]:
bt_copy

In [ ]:
bt.style().button_color = "red";
bt_copy.style().button_color = "green";

Link widget


In [ ]:
#include "xwidgets/xslider.hpp"
#include "xwidgets/xlink.hpp"
#include "xwidgets/xbox.hpp"

In [ ]:
xw::slider<double> s1, s2;

s1.description = "Slider 1";
s2.description = "Slider 2";

In [ ]:
auto l = xw::link(s1, "value", s2, "value");

In [ ]:
s1

In [ ]:
s2

In [ ]:
xw::slider<double> source, target;

In [ ]:
auto dl = xw::directional_link(source, "value", target, "value");

In [ ]:
source

In [ ]:
target

Box widgets


In [ ]:
#include "xwidgets/xbutton.hpp"
#include "xwidgets/xslider.hpp"
#include "xwidgets/xbox.hpp"

In [ ]:
xw::vbox b;
xw::slider<double> slid;

In [ ]:
b.add(xw::button())

In [ ]:
b.add(slid)

In [ ]:
b